package com.codegeek.framework;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * @author wj
 * @ClassName
 * @Description  系统变量初始化,主库启动，从库不要启动
 * @date 2020-03-31
 */
@Component
public class CGInitialCheck implements ApplicationRunner {
    public static final Logger logger = LogManager.getLogger("FileUtils");

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        try{
            //强制让所有传感器设备离线
            String sql="update slope_device set state = 0 ,online_time = null where state = 1 or state = 0";
            jdbcTemplate.update(sql);

        }catch (Exception e){
            e.printStackTrace();
            logger.error(e);
        }
    }
}
